

setInterval

// handle: (resolve, reject) => void
function MyPromise(hander) {

  let state = 0;
  let thenQueue = [];
  let catchQueue = [];

  hander.call(null, (args) => {
    // resolve
    state = 1
    thenQueue.forEach(func => func(args));
  }, (args) => {
    // reject
    state = 2
    catchQueue.forEach(func => func(args))
  })

  return {
    then: function (func) {
      thenQueue.push(func);
      return this;
    },
    catch: function (func) {
      catchQueue.push(func);
      return this;
    }
  }
}

console.log('22')
new MyPromise((resolve, reject) => {
  setTimeout(() => {
    resolve();
  }, 1000)
}).then(() => {
  console.log('then')
}).catch(() => {
  console.log('catch')
}).then(() => {
  console.log('then 2')
})